/* String Service : class avec des méthodes sur la manipulation des chaines de caractères */
function StringManagerModel ($http, $rootScope) {
	return {
        TraitementUrl: function (chaine) {
            var tableauParametresUrl = chaine.split("//");
            var urlRetour = "";

            angular.forEach(tableauParametresUrl, function(item) {
                urlRetour += this.ReecritureParametresUrl (item);
                urlRetour += "/";
            }, this);
            
            return urlRetour.substring(0, urlRetour.length-1);
        },
        ReecritureParametresUrl: function (chaine) {
            var r = chaine.toLowerCase();
            r = r.replace(new RegExp("\\s", 'g'), "-");

            r = this.RetirerAccents(r);

            r = r.replace(new RegExp("\\W", 'g'), "-");
            r = r.replace(new RegExp("[-]+", 'g'), "-");
            r = r.replace(new RegExp("[-]$", 'g'), "");

            return r;
        },
        RetirerAccents: function (chaine) {
            var r = chaine.toLowerCase();
            r = r.replace(new RegExp("[àáâãäå]", 'g'), "a");
            r = r.replace(new RegExp("æ", 'g'), "ae");
            r = r.replace(new RegExp("ç", 'g'), "c");
            r = r.replace(new RegExp("[èéêë]", 'g'), "e");
            r = r.replace(new RegExp("[ìíîï]", 'g'), "i");
            r = r.replace(new RegExp("ñ", 'g'), "n");
            r = r.replace(new RegExp("[òóôõö]", 'g'), "o");
            r = r.replace(new RegExp("œ", 'g'), "oe");
            r = r.replace(new RegExp("[ùúûü]", 'g'), "u");
            r = r.replace(new RegExp("[ýÿ]", 'g'), "y");
            return r;
        },
        getUrlParameters: function (parameter, staticURL, decode) {
           /*
            Function: getUrlParameters
            Description: Get the value of URL parameters either from 
                         current URL or static URL
           */
            var currLocation = (staticURL.length)? staticURL : window.location.search;

            if( currLocation == "" ) return false;

            var parArr = currLocation.split("?")[1].split("&");
            var returnBool = true;
           
           for(var i = 0; i < parArr.length; i++){
                parr = parArr[i].split("=");
                if(parr[0] == parameter){
                    return (decode) ? decodeURIComponent(parr[1]) : parr[1];
                    returnBool = true;
                }else{
                    returnBool = false;            
                }
           }
           
           if(!returnBool) return false;  
        },
        isEmpty: function (obj) {
            for(var prop in obj) {
                if(obj.hasOwnProperty(prop))
                    return false;
            }

            return true;
        },


    };
}
